#include "stdafx.h"

bool InCallBack=false;
LPVOID CallBackParam;
bool AbortPatch=false;
void PutStatus(char* status){MyPrintf("%s",status);}
int lastpc=-1;
void PutPct(int pc){if (lastpc!=pc) MyPrintf("\r%3u%%\r",lastpc=pc);}
void PutCopyright(char* VersionLine, char*Ptr2 ){MyPrintf("%s\n%s\n",VersionLine,Ptr2);};

bool VersionSet;
char VersionLine[1024]="1.0";

LPVOID CALLBACK PatchCallBack( UINT Id, LPVOID Parm )
{
  LPVOID RetVal;

  CallBackParam = Parm; 
  InCallBack=TRUE;
  RetVal = "";

  switch( Id )
  {
    case 0xc:
      // set copyright string
      // parse it - format is sep line, centered line 1 (product name),
      //	centered line 2 (platform/edition info), then second call has centered line 3
      //	( copyright info), sep line, blank line

	case 1:
    case 3:

    case 9:
    case 0xa:
    case 0xb:
      // these are all text output...
		PutStatus((char*)Parm);
      break;

	case 7:
      // begin patch
		MyPrintf("Processing: %s\n",Parm);
      break;

    case 8:
      // end patch 
      PutStatus(" ");

      PutPct( 0 );
      break;

    case 2:
      // warning 
      OemToAnsi(  (const char *) Parm,  (char *) Parm );
      if (IDCANCEL ==InformError("Patch Warning",  (const char *) Parm, MB_OKCANCEL|MB_ICONEXCLAMATION ));
	  AbortPatch = TRUE;
      break;

    case 4:
      // error
      OemToAnsi( (const char *) Parm,  (char *) Parm );
      InformError( "Patch Error",  (const char *) Parm, MB_ICONSTOP | MB_OK );
      break;

    case 5:
      // % complete
      PutPct( (int) (((long)(0xffff & *((UINT *) Parm))*100L)/0x8000L) );
      break;

    case 6:
      // Number of patch files
      break;

    case 0xd:
      // this one shouldn't happen (only occurs if the patch file
      //   file bound to the executable is invalid in some way).
      InformError( "Abort",  "Callback 0D", MB_OK );
      AbortPatch = TRUE;
      break;

    case 0xe:
      // this one shouldn't happen either (same reason)
      break;

    case 0xf:
      // Do password dialog here (abort in this skeleton)
      AbortPatch = TRUE;
      break;

    case 0x10:
      // Incorrect password alert
      break;

    case 0x11:
      // do disk change dialog (abort in this skeleton)
      AbortPatch = TRUE;
      
      break;

    case 0x12:
      // Invalid disk alert (abort in this skeleton)
      AbortPatch = TRUE;
      break;

    case 0x13:
      // system location confirmation (always returns "Y" in this skeleton)
      RetVal = "Y";
      break;
      
    case 0x14:
      // Do Location Dialog (abort in this skeleton)

      AbortPatch = TRUE;
      break;
      
     case 0x16:
       PutStatus( "Searching for Systems to Update..." );
       PutPct( 0 );
       break;
       
     case 0x15:
    default:
      break;

  } 

  InCallBack = FALSE;

  if (AbortPatch)
    return (NULL);
  else
    return (RetVal);
}
